<%--
  Created by IntelliJ IDEA.
  User: 32650
  Date: 2023-05-06
  Time: 0:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%
    String message = request.getAttribute("message") == null ? "" : request.getAttribute("message").toString();
%>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="css/Registration.css" rel="stylesheet">
    <title>注册</title>
</head>
<body>
<div class="register-container">
    <h1>注册</h1>
    <% if (request.getParameter("message") != null) { %>
    <div class="success-message">
        <%= request.getParameter("message") %>
    </div>
    <% } %>
    <form action="registration" method="post" onsubmit="return check()">
        <label for="name">姓名:</label>
        <input type="text" id="name" name="name">
        <label for="username">用户名:</label>
        <input type="text" id="username" name="username">
        <label for="password">密码:</label>
        <input type="password" id="password" name="password">
        <label for="confirm-password">确认密码:</label>
        <input type="password" id="confirm-password" name="confirm-password">
        <label for="phone">手机号:</label>
        <input type="text" id="phone" name="phone">
        <input type="submit" class="button">
    </form>
    <a href="Login.jsp">已有账号？</a>
</div>
</body>
<script>
    function check() {
        let password = document.getElementById("password").value;
        let confirm_password = document.getElementById("confirm-password").value;
        if (password !== confirm_password) {
            alert("两次密码不一致");
            return false;
        } else {
            return true;
        }
    }

    let message = "<%=message%>";
    if (message === "true") {
        alert("注册成功");
    } else if(message === "false"){
        alert("注册失败");
    }
</script>
</html>